var purchaseStore = Ext.create('A4.store.procuremanager.PurchaseListStore');

var purchaseRowEdit = Ext.create('Ext.grid.plugin.RowEditing', {
	clicksToEdit : 2,
	autoCancel : false
});

Ext.define('A4.view.desktop.procuremanager.PurchaseManager',{
	extend:'Ext.grid.Panel',
	id:'purchase-manager-win',
	//显示此窗口时遮罩其他组件
    border: false,
    store : purchaseStore,
	columns: [
              {
                  text: "条码",
                  flex:1,
                  sortable: true,
                  dataIndex: 'barcode',
                  editor : {
          			allowBlank : true
          		}
              },
              {
                  text: "品牌",
                  width: 40,
                  sortable: true,
                  dataIndex: 'brand',
                  editor : {
          			allowBlank : true
          		}
              },
              {
                  text: "商品名称",
                  width: 60,
                  sortable: true,
                  dataIndex: 'productName',
                  editor : {
          			allowBlank : true
          		}
              },
              {
            	  text: "采购状态",
                  width: 60,
                  sortable: true,
                  dataIndex: 'ProStatus',
                  editor : {
          			allowBlank : true
          		}
              },
              {
            	  text: "销售状态",
                  width: 60,
                  sortable: true,
                  dataIndex: 'salesStatus',
                  editor : {
          			allowBlank : true
          		}
              },
              {
            	  text: "进价",
                  width: 40,
                  sortable: true,
                  dataIndex: 'PurPrice',
                  editor : {
          			allowBlank : true
          		}
              },
              {
            	  text: "补货数量",
                  width: 60,
                  sortable: true,
                  dataIndex: 'repQuantity',
                  editor : {
          			allowBlank : true
          		}
              }
          ],
          plugins : [purchaseRowEdit],
          tbar : [ {
      		text : 'Add',
      		iconCls:'add',
      		id:'purchase-add',
      		handler : function() {
        	  purchaseRowEdit.cancelEdit();
      			var r = Ext.create('A4.model.procuremanager.PurchaseModel', {

      				barcode:'',
      				brand:'',
      				productName:'',
      				ProStatus:'',
      				salesStatus:'',
      				PurPrice:'',
      				repQuantity:''
      			});

      			purchaseStore.insert(0, r);
      			purchaseRowEdit.startEdit(0, 0); 
      		}
      	}, {
      		id : 'purchase-remove',
      		text : 'Remove',
      		iconCls:'remove',
      		handler : function() {
      			var sm = Ext.getCmp('purchase-manager-win').getSelectionModel();
      			purchaseRowEdit.cancelEdit();
      			purchaseStore.remove(sm.getSelection());
      			if (purchaseStore.getCount() > 0) {
      				sm.select(0);
      			}
      		},
      		disabled : true
      	} ],
      	listeners : {
      		'selectionchange' : function(view, records) {
      			Ext.getCmp('purchase-remove').setDisabled(!records.length);
      		}
      	}
	
	
	
});